package com.los.rabbitmq.simple;

import com.los.rabbitmq.utils.ConnectionUtils;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @program: rabbitmq
 * @description: 发送消息
 * @author: Yujuan
 * @create: 2018-08-01 21:38
 **/
public class Send {
    private static final String QUEUE_NAME="los_simple_queue";
    public static void main(String[] args) throws IOException, TimeoutException {
        //获取一个连接
        Connection connection= ConnectionUtils.getConnection();
        //创建一个通道
        Channel channel=connection.createChannel();
        //通过通道创建一个队列
        channel.queueDeclare(QUEUE_NAME,false,false,false,null);
        String msg="Hello Simple Rabbitmq";

        //发送消息
        channel.basicPublish("",QUEUE_NAME,null,msg.getBytes());

        channel.close();
        connection.close();
    }
}
